﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSerialPortInfo>
#include <QComboBox>
#include <QSerialPort>  // 添加串口类
#include <QPushButton>  // 添加按钮类
#include <QMessageBox>  // 添加消息框
#include "RngLib.h"
#include <stdint.h>
#include"qdebug.h"
#define TXHead 0xABFBCDFB
#define TXTial 0x0FAFBFCF

extern uint32_t ts_back;


typedef struct{
    uint32_t head;
    uint32_t id;
    uint64_t sum;
    uint32_t len;
    uint64_t Time_Stamp;
    uint32_t freq;
    uint32_t tail;
}debug_struct;



typedef struct{
    uint32_t head;
    uint32_t id;
    uint32_t len;
    uint32_t taskId;
    uint32_t freq;
}HEAD_DATA_MESSAGE;




typedef struct{
    uint32_t head;
    uint32_t id;
    uint32_t len;
    uint32_t data0;
    uint32_t data1;
    uint32_t data2;
    uint32_t tail;
}NewF_Collect_Message;





typedef struct
{
    uint32_t head;
    uint32_t id;
    uint32_t len;
    uint32_t taskId;
    uint32_t freq;
    uint8_t E901[4096];
    uint8_t E895[4096];
    uint64_t checkSum;
    uint32_t tail;
} NewF_Collectdata;




typedef struct
{
    uint8_t headAndId;   /* bit7~4=0xC, bit3~0=DeviceID(1~F) */
    uint8_t cmd;
    uint8_t data0;
    uint8_t data1;
    uint8_t data2;
} AGILE_HEAD;




QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();
    void on_pushButton_connect_clicked();
    void on_pushButton_hexMode_clicked();
    void on_pushButton_clear_clicked();

    void on_pushButton_set_freq_clicked();

    void on_pushButton_set_mode_clicked();
    void on_pushButton_echarts_clicked();

    void on_pushButton_setstatus_clicked();

    void on_pushButton_checkstatus_clicked();

private:
    Ui::MainWindow *ui;
    void serialPortInit();
    void readSerialData();
    QSerialPort *serialPort;    // 串口对象
    bool isConnected;         // 连接状态标志
    bool isHexMode;           // 十六进制显示模式标志
    RING_ID serialRingBuffer;
    NewF_Collect_Message Collect_Msg;
    NewF_Collectdata *Collect_data;
    // 非模态实时绘图窗口及其 Plot
    class QDialog *echartsDialog = nullptr;
    class QCustomPlot *echartsPlot = nullptr;
    class QCustomPlot *echartsPlot2 = nullptr;
};

#endif // MAINWINDOW_H

